package Tree;

public class sortedArrayToBST {
    public static TreeNode sortedArrayToBST(int[] num) {
        // Note: The Solution object is instantiated only once and is reused by each test case.
        return sortedArrayToBST(num,0,num.length-1);
        
    }
    
    public static TreeNode sortedArrayToBST(int[] num, int start, int end){
        if(start>end) return null;
        int flag = (end+start)/2;
        TreeNode to_return = new TreeNode(num[flag]);
        to_return.left = sortedArrayToBST(num,start,flag-1);
        to_return.right = sortedArrayToBST(num,flag+1,end);
        return to_return;
    }
    
    public static void main(String[] args){
    	int[] temp = {0,1,2,3,4,5};
    	sortedArrayToBST(temp);
    }
}